package cn.kgc.springbootdemo.service.impl;

import cn.kgc.springbootdemo.entity.UserRole;
import cn.kgc.springbootdemo.mapper.UserRoleMapper;
import cn.kgc.springbootdemo.service.UserRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {


    @Override
    public Boolean insertOne(UserRole userRole) {
        return baseMapper.insert(userRole) > 0 ? true : false;
    }

    @Override
    public Boolean deleteOne(String userId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("user_id", userId);
        return baseMapper.deleteByMap(map) > 0 ? true : false;
    }

    @Override
    public Boolean isVipByUserId(String userId) {
        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id","3");
        queryWrapper.eq("user_id",userId);
        return baseMapper.selectCount(queryWrapper) > 0 ? true : false;
    }
}
